package org.emergency.framework.dao.upDownLoad.impl;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

import org.emergency.framework.dao.HibernateBaseDao;
import org.emergency.framework.dao.upDownLoad.IFileUploadDAO;
import org.emergency.framework.model.FileUpload;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

@Repository("fileUploadHibernateDAO")
public class FileUploadHibernateDAO extends HibernateBaseDao<FileUpload> implements
		IFileUploadDAO {

	@SuppressWarnings("unchecked")
	public List<FileUpload> getFileUploads(String tmpId){
		return getHibernateTemplate().find("FROM FileUpload WHERE fileSrcName = '"+tmpId +"'");
	}
	
	@SuppressWarnings("unchecked")
	public FileUpload getFileUploadByPackAndName(String srcName,String saveName){
		System.out.println("这是getFileUploadByPackAndName方法");
		FileUpload fileUpload=null;
		try {
			List list =  getHibernateTemplate().find("FROM FileUpload WHERE fileSrcName ='"+srcName+"' AND fileSaveName = '"+saveName+"'");
			fileUpload = null;
			if(list.size()>0){
				fileUpload = (FileUpload)list.get(0);
			}
		} catch (DataAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return fileUpload;
	}


	@SuppressWarnings("unchecked")
	public void deleteFileUpload(Class clazz, Serializable id) {
		getHibernateTemplate().delete(this.getFileUpload(clazz, id));
		
	}

	@SuppressWarnings("unchecked")
	public FileUpload getFileUpload(Class clazz, Serializable id) {
		return (FileUpload)getHibernateTemplate().get(clazz, id);
	}

	@SuppressWarnings("unchecked")
	public void deleteAll(Collection entities) {
		getHibernateTemplate().deleteAll(entities);
		
	}
}
